{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Understanding word vectors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "pd.set_option('max_rows', 25)\n",
    "plt.style.use('ggplot')\n",
    "plt.rcParams[\"figure.figsize\"] = (10, 4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "... for, like, actual poets. By [Allison Parrish](http://www.decontextualize.com/)\n",
    "\n",
    "In this tutorial, I'm going to show you how word vectors work.\n",
    "\n",
    "## Why word vectors for poetry?\n",
    "\n",
    "Tzara proposed a method of composing a Dada poem: cut out the words of a text, shake them in a bag, then write down the words as you remove them at random from the bag. The very idea caused a riot and sundered the avant garde in twain (or so the story goes). For poets, word vectors are (for better or worse) a tool to help soften the blow of cut-up techniques: instead of selecting words at random, we might select units of text that are *close in meaning* to other units. This can yield poetic juxtapositions with subtle effects impossible to achieve with other techniques.\n",
    "\n",
    "Also, it's fun!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Animal similarity and simple linear algebra\n",
    "\n",
    "We'll begin by considering a small subset of English: words for animals. Our task is to be able to write computer programs to find similarities among these words and the creatures they designate. To do this, we might start by making a spreadsheet of some animals and their characteristics. In Python, you'd define such a spreadsheet like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "animals = [\n",
    "    {'name': 'kitten', 'cuteness': 95, 'size': 15},\n",
    "    {'name': 'hamster', 'cuteness': 80, 'size': 8},\n",
    "    {'name': 'tarantula', 'cuteness': 8, 'size': 3},\n",
    "    {'name': 'puppy', 'cuteness': 90, 'size': 20},\n",
    "    {'name': 'crocodile', 'cuteness': 5, 'size': 40},\n",
    "    {'name': 'dolphin', 'cuteness': 60, 'size': 45},\n",
    "    {'name': 'panda bear', 'cuteness': 75, 'size': 40},\n",
    "    {'name': 'lobster', 'cuteness': 2, 'size': 15},\n",
    "    {'name': 'capybara', 'cuteness': 70, 'size': 30},\n",
    "    {'name': 'elephant', 'cuteness': 65, 'size': 90},\n",
    "    {'name': 'mosquito', 'cuteness': 1, 'size': 1},\n",
    "    {'name': 'goldfish', 'cuteness': 25, 'size': 2},\n",
    "    {'name': 'horse', 'cuteness': 50, 'size': 50},\n",
    "    {'name': 'chicken', 'cuteness': 25, 'size': 15}\n",
    "]\n",
    "animal_lookup = {item['name']: (item['cuteness'], item['size']) for item in animals}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And then display it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>cuteness</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>kitten</td>\n",
       "      <td>95</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>hamster</td>\n",
       "      <td>80</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>tarantula</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>puppy</td>\n",
       "      <td>90</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>crocodile</td>\n",
       "      <td>5</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>dolphin</td>\n",
       "      <td>60</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>panda bear</td>\n",
       "      <td>75</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>lobster</td>\n",
       "      <td>2</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>capybara</td>\n",
       "      <td>70</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>elephant</td>\n",
       "      <td>65</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>mosquito</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>goldfish</td>\n",
       "      <td>25</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>horse</td>\n",
       "      <td>50</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>chicken</td>\n",
       "      <td>25</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          name  cuteness  size\n",
       "0       kitten        95    15\n",
       "1      hamster        80     8\n",
       "2    tarantula         8     3\n",
       "3        puppy        90    20\n",
       "4    crocodile         5    40\n",
       "5      dolphin        60    45\n",
       "6   panda bear        75    40\n",
       "7      lobster         2    15\n",
       "8     capybara        70    30\n",
       "9     elephant        65    90\n",
       "10    mosquito         1     1\n",
       "11    goldfish        25     2\n",
       "12       horse        50    50\n",
       "13     chicken        25    15"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(animals, columns=['name', 'cuteness', 'size'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This table associates a handful of animals with two numbers: their cuteness and their size, both in a range from zero to one hundred. (The values themselves are simply based on my own judgment. Your taste in cuteness and evaluation of size may differ significantly from mine. As with all data, these data are simply a mirror reflection of the person who collected them.)\n",
    "\n",
    "These values give us everything we need to make determinations about which animals are similar (at least, similar in the properties that we've included in the data). Try to answer the following question: Which animal is most similar to a capybara? You could go through the values one by one and do the math to make that evaluation, but visualizing the data as points in 2-dimensional space makes finding the answer very intuitive:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgQAAAHmCAYAAAAMZpaCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzs3X1cVHX+///HAImgpigIAWZ7S1GuTLwCpQtN00oRUho1rSwvcls0ycrMtNa+W1p5laX+SnfTpOSsaai5lqZmWmEfUFPEq8xSCFYFUhFFYH5/gLOOYokwA+jzfrt1a+Z9zvuc17zBM0/Oec8Zk8ViQURERG5sTtVdgIiIiFQ/BQIRERFRIBAREREFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREAJfqLuAa6NaKIiJyozHZewe1MRCQmZl5zX09PT05fvx4FVYjoHG1F42r/Whs7UPjWvV8fX0dsh9dMhAREREFAhEREVEgEBERERQIREREBAUCEZFqM336dEaPHl3p7Rw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HP//5T+bMmUObNm3o2LEj8+bNw2L53ze+x8bGEh8fT9u2bTl37hyvvfbaVdUwadIkVqxYQUBAAM8//zx9+/a96vojIyMJCAggLCyMkJCQq+4ntY/p4l+2WsKirz+ueTSu9qFxtZ/aNraxsbH069ePRx55pLpL+UO1bVxrg7K5I3a/dqM5BCIilVRyLAuSErDk5WBq1BiiB+Pk5VPdZYlUiAKBiEgllBzLwjJzMhzLAsACcGgfJfFTFAqkVlEgEBGpjKQEaxiwKjtjwPBxVbabZcuWVdm2RMqjSYUiIpVgycupULtITaVAICJSCaZGjSvULlJTKRCIiFRG9GC4dK6Al09pu0gtojkEIiKV4OTlQ0n8FH3KQGo9BQIRkUpy8vKp0gmEItVBlwxEREREgUBEREQUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIREREBXBy1I7PZHA8MByzALuAJ4BZgKdAYSAUeNQyj0FE1iYiISCmHnCEwm81+wBigg2EYIYAzMBCYBsw0DKMlkAsMc0Q9IiIiYsuRlwxcADez2ewCuAO/AfcCy8qWLwJiHFiPiIiIlHHIJQPDMDLMZvPbwK9AAfAlkALkGYZRVLbaUcCvvP5ms3kkMLJsW3h6el5zLS4uLpXqL+XTuNqHxtV+NLb2oXGtvRwSCMxmswcQDfwFyAP+DTxQzqqW8vobhvE+8P6FdY4fP37NtXh6elKZ/lI+jat9aFztR2NrHxrXqufr6+uQ/TjqkkEP4GfDMI4ZhnEeWA50ARqVXUIA8AcyHVSPiIiIXMRRnzL4FYgwm83ulF4y6A78H7ARiKX0kwaPA0kOqkdEREQu4pAzBIZhJFM6eTCV0o8cOlF6CWA88KzZbD4INAEWOqIeERERseWw+xAYhvEK8MolzYeAT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iouLv7zla4TFblkgGEY+w3D+OmS57uqvqzrQ0ZGBsOHDyc0NJTg4GAmTpxIYmIi0dHRvPLKKwQHBzN9+nRKSkqYNWsWnTp1ok2bNowZM4aTJ09at7Nt2zb69u1LYGAgHTp0IDExEYCTJ08yZswYQkND6dSpE7NmzaKkpAQo/SWeMmUKISEhdO7cma+++sqmttjYWD7++ONy6z548CADBw4kODiYu+66i5UrV9pphESkpgkPD2fOnDl07dqVoKAg4uPjOXv2LAB5eXk89thjhIaGEhQUxGOPPcbFN4qLjY3l1VdfJTo6moCAAAYNGkROzv9uC71s2TI6depEcHAws2fPttnv9u3biYqKIjAwkLCwMCZOnEhhYeEf1rp06VLatWtHWFgY8+fPt7aXlJTw7rvv0qVLF4KDg3nqqafIzc21Lh85ciRt27aldevW9OvXj3379lmXjR07lhdffJFHH32UFi1asHXr1msbyFqoQoFArl5xcTGPP/44fn5+JCcnk5KSQnR0NFD6i9+8eXN27tzJmDFjMAyDf//73/z73//mu+++48yZM0ycOBEoDRVDhgzhySef5Mcff+TLL78kODgYgJdffplTp07x3Xff8emnn7Js2TJrWEhISGD9+vV88cUXrFmzhtWrV19V3WfOnGHgwIE89NBD7Ny5k7lz5/LSSy/Z/IMRkevbihUrSEhIYOvWrRw6dMj65l1SUsKAAQPYtm0b27Zto27durz88ss2fZcuXcqMGTPYuXMn58+ft75R79+/nwkTJvDOO++QmppKbm4uv/32m7Wfs7Mzr776Krt27WLlypVs2bKFRYsW/WGd3377LVu2bOHjjz/mvffes85HWLhwIWvXrmXZsmWkpqbSsGFD6zEV4N5772XLli3s3LmTkJAQ4uLibLb72WefMWbMGPbv30+nTp2ufSBrGQUCO9m+fTvZ2dlMmjQJd3d36tata/3F8vb25sknn8TFxQU3NzeWL1/OiBEjaN68OfXq1ePFF19k5cqVFBUVsXz5cu666y5iYmK46aabaNy4MSEhIRQXF7Nq1SomTJhA/fr1adasGU899RSffvopAKtWrWL48OH4+fnh4eHB6NGjr6rudevW0axZMwYMGICLiwuh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RP0UxdEalVdOySK6nuWxePB5aazeb/B2wHFlZzPRXi5OUDw8dVdxkiIhWiY5eUx+GBwDCMTcCmsseHgBvnuyVFRERqKN26WERERBQIRERERIFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERG5CkeOHMHPz4+ioqLqLkXsRIFAREREFAhERMSxdJahZlIgEBGppTIyMhg+fDihoaEEBwczceJEDh8+zMMPP0xwcDAhISHExcXx+++/W/uEh4czZ84cunbtSlBQEPHx8Zw9exaAe++9ly+//NK67vnz5wkJCWH37t3WtqVLl9KuXTvCwsKYP3++tX379u1ERUXRtGlTwsLCmDhxIoWFhdblfn5+fPjhh0RGRnLnnXcCMHnyZDp06ECrVq24//77SU5OtttYyZ9TIBARqYWKi4t5/PHH8fPzIzk5mZSUFKKjo7FYLIwePZrU1FS+/vprMjMzmT6lm5nZAAAgAElEQVR9uk3fFStWkJCQwNatWzl06BCzZ88GIDY2luXLl1vX27BhA97e3oSEhFjbvv32W7Zs2cLHH3/Me++9x+bNmwFwdnbm1VdfJTMzk5UrV7JlyxYWLVpks9+1a9eyevVqNm7cCMAdd9zBl19+SVpaGjExMTz11FPWcCKOp0AgIlILbd++nezsbCZNmoS7uzt169alU6dO/OUvf+Huu+/G1dWVJk2aMHLkSL7//nubvkOHDsXPzw8PDw/GjBlDUlISAP369WPDhg2cOnUKgGXLltG/f3+bvs8++yzu7u4EBgYyYMAAa982bdrQvn17XFxcaNasGUOGDLlsv3FxcXh4eODm5gZA//79ady4MS4uLowaNYrCwkJ++uknu4yX/DmX6i5AREQqLjMzE39/f1xcbA/jx48fZ9KkSWzbto3Tp09TUlJCw4YNbdbx9fW1Pvb39yc7OxsAHx8fOnbsyJo1a7j//vvZuHEjU6ZM+cO+e/fuBeCnn37i73//O7t37yY/P5+ioiLatG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pUAApdd6KtAu9qWfh4jUNtfDcUuBACB6MFx6jcfLp7RdHE8/DxGpba6D45YmFQJOXj6UxE+p1bNDryf6eYhIbXM9HLd0HwKpEhpX+9C42o/G1j40rlXPUfch0CUDERERUSAQERERBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQEREHCA8PZ/PmzdVdhvwBBQIREbnujR07lmnTplV3GTWaAoGIiMifKCoqqu4S7E6BQEREHGLPnj306NGD1q1bM2rUKM6ePUteXh6PPfYYoaGhBAUF8dhjj5GZmWntExsby7Rp0+jbty8tW7bk8ccfJycnh7i4OFq1asWDDz7IkSNHALBYLLzyyiu0adOG1q1b06NHD/bu3cuSJUtYsWIF8+bNs24DICsrixEjRhAaGkpERAQLFy607nf69OmMGDGC0aNH06pVKwzDcOxgVQMFAhERcYhVq1axZMkSvvvuO9LT0zEMg5KSEgYMGMC2bdvYtm0bdevW5eWXX7bpt3LlSt555x1SUlL45Zdf6Nu3L2azmbS0NFq0aMGMGTMA+Prrr0lOTuabb74hPT2defPm4eHhwZAhQ3jooYf461//yoEDB1i0aBElJSUMHTqUoKAgUlJSSExMZMGCBWzatMm63y+//JLevXuTnp7OQw895MihqhYKBCIi4hBPPvkkPj4+eHh4cN9995GWlkbjxo3p3bs3bm5u1K9fnzFjxvD999/b9DObzdx2223cfPPNdOvWjdtuu427774bFxcX+vTpw+7duwFwcXHh9OnTHDx4EIvFQsuWLfH29i63lh07dnDixAni4+OpU6cOzZs355FHHiEpKcm6Tvv27bn//vtxcnLCzc3NfgNTQ7hUdwEiInJj8PLysj52c3MjOzubgoICXnnlFTZt2sTvv/8OwOnTpykuLsbZ2fmyfnXr1sXT09Pm+ZkzZwC48847eeKJJ5g4cSIZGRk88MADTJo0iQYNGlxWy9GjR8nOziYwMNDaVlxcTHh4uPW5r69vFb3y2kGBQEREqs38+fM5dOgQq1evpmnTpuzevZtevXphsViuaXvDhg1j2LBhHD9+nFGjRjFv3jxe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ECcnJ4KCgoiOjua7776z2WZ8fDxubm4EBwcTFBTEnj17qqTWHj16cNttt2EymejcuTP33HMPycnJVbLtquLn58fPP/9c7rLExERiYmKsz3/44QciIyNp2bIla9euZciQIRiGUal9iIjUVLpTYQ1WXFzMtGnTWL16NSdOnMDJqTS/5eTkcPPNNwPg6+tr0yc1NZXXX3+dffv2cf78eQoLC+ndu7fNOk2bNrU+dnNzIz8/v0rq3bBhAzNmzODnn3+mpKSEgoICWrduXSXbrg5vvfUWTzzxBMOHDwfg/vvvr+aKRETsR2cIahiTyWR9vGLFCr744guWLl3K3r17+f777wGwWCzlrg8QFxdHz549+eGHH9i7dy9Dhgy5pn1f4O7uztmzZ63P//vf/5bb99y5c4wYMYJRo0axY8cO0tPTuffee21qrW0yMjIICAio7jJERBxCgaCG8fT05NdffwXg9OnT1KlTBw8PDwoKCpg6deqf9j99+jSNGjWibt26bN++nc8++6xC+z5y5AglJSXWtuDgYJKSkjh//jw7d+7k888/L7dvYWEhhYWFNGnSBBcXFzZs2MDXX3991fuuqF27dtGzZ08CAgIYOXIko0aNYtq0aQAkJCQQGRlJcHAwQ4cOJSsrq9xt5OTkMHToUFq1akXv3r355ZdfrMu6dOnCL7/8Yp3gee7cOWJjY/n4448B+Pnnn+nfvz+tW7cmJCSEUaNG2Wz7m2++ITIykqCgIF566aVaHYxE5MagQFDDjB49mtmzZxMYGEheXh7+/v60b9+erl270q5dOwB27tzJXXfdVW7/119/nbfffpuAgABmzpxJVFTUVe+7T58+AISEhNCrVy8Ann/+eX755ReCgoJ4++23eeihh8rt26BBA1577TVGjRpFUFAQK1asoGfPnhV56VetsLCQYcOGYTabSUtLIyYmxjpxcsuWLbzxxhvMnz+f1NRU/P39efrpp8vdzsSJE3F1dWX79u1Mnz6dxMRE67Jvv/3WZoKnq6urTd+33nqLu+++mz179vB///d/PPnkkzbL169fz5o1a1i3bh2rVq1i06ZNVTsIIiJVTHMIaphevXpZ34zL8/DDDwPYTH4LDw+3vkH16dPH+sZ+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nYqaV8G8J9J22VJz88A11ziufcAc4FFZrYHmOPu24FngJ8B/21mACvcfVEbv4eItIISApH4OwL0N7OMRknBaeCqpO2cRuc1bpo/Arzr7hNaGcNFz3X394ApZtYFeIxglcF+7v4Xgm6D2WH3wmYze8/dN7UiBhFpAyUEIvH3R6CU4Or734FzBAP7PgT+zcz6A18ATzU678/ADUnbb4XvcT9/HYMwEvg/d9/fTAwXPRc4CPwQeMvdvzCzL8MYMbNJwP+Ex9TtP9eC7y4i7USDCkVizt3PAZOBgcCnBIP0prp7EbAG2APsJPinnWwZ8AMzKzez/wiv1v8euBc4RtA9sBjoegkxNHfu/cDhMBl4BMgP9w8C3iFIHLYDP3f3P7SwCESkHei2QxEREVELgYiIiCghEBEREZQQiIiICEoIREREBCUEIiIighICERERQQmBiIiIoIRAREREgP8H7IYf6rxrPHgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 576x576 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(8, 8))\n",
    "plt.scatter([item[0] for item in animal_lookup.values()],\n",
    "            [item[1] for item in animal_lookup.values()])\n",
    "plt.xlabel('cuteness')\n",
    "plt.ylabel('size')\n",
    "for label, (cute, size) in animal_lookup.items():\n",
    "    plt.text(cute+1, size+1, label, fontsize=12)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The plot shows us that the closest animal to the capybara is the panda bear (again, in terms of its subjective size and cuteness). One way of calculating how \"far apart\" two points are is to find their *Euclidean distance*. (This is simply the length of the line that connects the two points.) For points in two dimensions, Euclidean distance can be calculated with the following Python function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "def distance2d(a, b):\n",
    "    return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(The `**` operator raises the value on its left to the power on its right.)\n",
    "\n",
    "So, the distance between \"capybara\" (70, 30) and \"panda\" (74, 40):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11.180339887498949"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distance2d(animal_lookup['capybara'], animal_lookup['panda bear']) # panda and capybara"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "... is less than the distance between \"tarantula\" and \"elephant\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "104.0096149401583"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distance2d(animal_lookup['tarantula'], animal_lookup['elephant']) # tarantula and elephant"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Modeling animals in this way has a few other interesting properties. For example, you can pick an arbitrary point in \"animal space\" and then find the animal closest to that point. If you imagine an animal of size 25 and cuteness 30, you can easily look at the space to find the animal that most closely fits that description: the chicken.\n",
    "\n",
    "Reasoning visually, you can also answer questions like: what's halfway between a chicken and an elephant? Simply draw a line from \"elephant\" to \"chicken,\" mark off the midpoint and find the closest animal. (According to our chart, halfway between an elephant and a chicken is a horse.)\n",
    "\n",
    "You can also ask: what's the *difference* between a hamster and a tarantula? According to our plot, it's about seventy five units of cute (and a few units of size).\n",
    "\n",
    "The relationship of \"difference\" is an interesting one, because it allows us to reason about *analogous* relationships. In the chart below, I've drawn an arrow from \"tarantula\" to \"hamster\" (in blue):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgQAAAHmCAYAAAAMZpaCAAAABHNCSVQICAgIfAhkiAAAAAlwSFl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KCAoGIiIigQCAiIiIoEIiIiAgKBCIiIgKYnXUgi8VSBfgACAJswBDgMBAJ1AbiAIthGMnOqpOIiIhkceYZgvnABsMwGgJNgIPAy8DXhmHUA77Ofi4iIiJO5pRAYLFYKgHtgCUAhmGkG4ZxDugGLM3ebCkQ5oz6iIiISF4mm83m8INYLJamwHvAAbLODkQDzwPxhmFUybVdsmEYnvmUHw4MBzAMo3l6evpt18VsNpORkXHb5SV/alfHULs6jtrWMdSuRa9s2bIAJkcfx1lzCMxAM2CUYRhRFotlPgUYHjAM4z2yAgWA7fTp07ddkerVq1OY8pI/tatjqF0dR23rGGrXoufj4+OU4zhrDsEJ4IRhGFHZz1eSFRCSLBbLPQDZ///PSfURERGRXJwSCAzDSASOWyyWBtmLHiVr+GAtMCh72SBgjTPqIyIiInk57WuHwChgucViKQvEAs+SFUgMi8XyHPA70MuJ9REREZFsTgsEhmHsAe7PZ9WjzqqDiIiI5E9XKhQREREFAhEREVEgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQEQcLDQ0lG3bthV3NUTkJhQIRERERIFAREq+jIyM4q6CyB1PgUBEHO7AgQN06NCBhg0bMmLECNLS0gBYvnw5bdu2JTAwkMGDB5OYmGgv4+vry4cffkjbtm154IEHsNlsTJkyhcaNG9OwYUM6dOjAoUOHALh8+TJTp06lRYsWNGnShPHjx5Oamlosr1WktFIgEBGHW7duHcuWLWPnzp0cPHgQwzDYvn0706dPZ/HixcTExODn58ff//73POU2bNjA+vXr2bJlC99++y1RUVF89913HDx4kEWLFuHp6QnAm2++SWxsLJs2bWLHjh0kJiYyb9684nipIqWWAoGIONyQIUOoWbMmnp6ePPbYY+zfv5/Vq1fTp08fgoODcXNzY8KECURHR3P8+HF7uZEjR+Lp6YmHhwdms5mLFy9y9OhRbDYb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uZ7PBOYahlEPSAaec3J9bpv1VCK2uZOxRX0Lh/dii/oW29zJWX9oIiIllN675HqcFggsFosf0An4IPu5CXgEWJm9yVKg9NxhZ81yuPoPKDt1i4iUWDd574qKirrt4QIp3Zw5ZDAPGAdUzH5eDThnGEbOxfxPAPl+Wd5isQwHhgMYhkH16tVvuxJms7lQ5XOcTbnAlfz2n3KBqkWw/9KmqNpV8lK7Os7d2raOfu+6W9v1TuCUQGCxWDoD/zMMI9pisbTPXpzfBIl8ZzgahvEe8F7ONoWZsFJUE16s5SvmuzyjfMW7ckKNJhI5htrVce7WtnX0e9fd2q6O5KwLJTlryKAt0NViscSRNYnwEbLOGFSxWCw5ocQPuP2vDzhbt/5w9SQcr5pZy0VESiq9d8l1OOUMgWEYE4AJANlnCF40DKO/xWL5D9CTrJAwCFjjjPoUBRevmljDp2qmroiUKnrvkusp7ksXjwdWWCyWfwK7gSXFXJ8CcfGqCUPHFnc1REQKRO9dkh+nBwLDMLYCW7MfxwJ3z70lRURESihdulhEREQUCERERESBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhERuQXHjx/H19eXjIyM4q6KOIgCgYiIiCgQiIiIc+ksQ8mkQCAiUkrFx8czdOhQgoODCQwMZOLEicTFxdGrVy8CAwMJCgpi5MiR/PHHH/YyoaGhRERE0L59ewICAggPDyctLQ2ARx55hE2bNtm3vXLlCkFBQezbt8++bMWKFTRr1oyQkBAWL15sX7579266dOlCjRo1CAkJYeLEiaSnp9vX+/r68uGHH9K2bVseeOABACZPnsz9999PgwYNeOKJJ4iKinJYW8nNKRCIiJRCmZmZDBo0CF9fX6KiooiOjqZbt27YbDZGjRpF9dtpAAAgAElEQVRFTEwM3377LQkJCcyePTtP2dWrV7N8+XJ27NhBbGws8+fPB6Bnz56sWrXKvt0333yDt7c3QUFB9mXff/8927dv55NPPuHdd99l27ZtALi6uvLaa6+RkJDA2rVr2b59O0uXLs1z3A0bNrB+/Xq2bNkCQJMmTdi0aRP79+8nLCyMv/71r/ZwIs6nQCAiUgrt3r2bpKQkJk2aRLly5XB3d6dly5bUqVOHdu3a4ebmRrVq1Rg+fDg//PBDnrKDBw/G19cXT09PRo8ezZo1awDo3r0733zzDRcuXABg5cqV9OjRI0/ZF154gXLlytGoUSN69+5tL9u4cWOaN2+O2WzG39+fAQMGXHPckSNH4unpiYeHBwA9evSgatWqmM1mRowYQXp6Or/++qtD2ktuzlzcFRARkYJLSEjAz88Psznv2/jp06eZNGkSu3bt4uLFi1itVipXrpxnGx8fH/tjPz8/kpKSAKhZsyYtWrTgyy+/5IknnmDLli1MnTr1hmUPHToEwK+//srrr7/Ovn37SElJISMjg8aNG1+3LMDixYv59NNPSUpKwmQyceHCBc6ePXubLSKFpTMEIiKlkI+PD/Hx8ddM0Js+fTomk4nNmzdz+PBhIiIisNlsebZJSEiwP46Pj8fb29v+vFevXnz22WesX7+e5s2bc88999xS2QkTJlC3bl3279/P4cOHefnll685rslksj+Oiopi4cKFLF68mAMHDnDw4EEqVap0TRlxHgUCEZFSKCQkhBo1ajBt2jQuXbpEWloaP/74IxcvXqR8+fJUrlyZkydPsmjRomvKLl26lISEBJKTk4mIiKBLly72dR07dmTfvn0sWbKEnj17XlN23rx5pKamcvjwYSIjI+natSsAKSkpVKxYkQoVKnD06FE++uijG9b/4sWLmM1mqlWrRkZGBnPnzrUPVUjxUCAQESmFXF1dWbp0KXFxcbRo0YL777+ftWvX8sILL7B3714aNmzIM888w5NPPnlN2bCwMPr160ebNm249957GTNmjH2dh4cHTz31FL///jtPPfXUNWVbtWpF27Zt6d27NyNGjOChhx4CYNKkSaxevZpq1arx0ksv2YPC9bRv356HH36YBx98kNDQUNzc3K4ZUhDnMpXC0zO23KesCqp69eqcPn26CKsjoHZ1FLWr45SGtrWeSoQ1y7GdO4upSlXo1h8Xr5qF2mdoaCizZs2iXbt2191m7ty5xMbGEhERUeD9l4Z2LW2yg5LpZtsVliYVioiUQNZTidjmToZTiQDYAGIPYw2fWuhQcCPJycl8+umnLFiwwGHHkJJJQwYiIiXRmuX2MGCXfcbAUZYvX06LFi14+OGHadWqlcOOIyWTzhCIiJRAtnP5f/3uestv1Y2uBti/f3/69+9fqP1L6aUzBCIiJZCpStUCLRcpLAUCEZGSqFt/uHqugFfNrOUiDqAhAxGREsjFqybW8KlF/i0DketRIBARKaFcvGrC0LHFXQ25S2jIQERERBQIRERERIFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIRERFBgUBERERQIBAREREUCERERAQFAhEREUGBQERERFAgEBERERQIREREBAUCERERQYFAREREUCAQERERFAhEREQEBQIREZE8QkNDiYiIoH379gQEBBAeHk5aWhqRkZGEhYXl2dbX15djx44BMGbMGMaPH0+fPn2oX78+PXr04MSJE3m2XbJkCa1btyYoKIg33ngDq9XK5cuXCQwM5ODBg/ZtT58+zX333ceZM2ec86JRIBAREbnG6tWrWb58OTt27CA2Npb58+ffcrkxY8awd+9eAgMDGTlyZJ71//d//8eXX37Jxo0b2bhxIytWrMDNzY2uXbuyatUq+3aff/45DzzwANWqVSvS13UjCgQiIiJXGTx4ML6+vnh6ejJ69GjWrFlzS+UeffRRWrVqhZubG+PHjyc6Opr4+Hj7+n/84x94enri6+vL0KFD+fzzzwHo1asXq1evxmq1AvDZZ5/Ro0ePon9hN6BAICIichUfHx/7Yz8/P5KSkgpcrnz58lSpUiVP2evtt1mzZpQrV46dO3dy9OhR4uLiePzxxwv7MgrE7NSjiYiIlAIJCQn2x/Hx8Xh7e1OuXDlSU1Pty//3v//dsFxKSgrnzp3D29s7z/oGDRrk2W+OXr16sWrVKry8vOjUqRPu7u5F+ppuRmcIRERErrJ06VISEhJITk4mIiKCLl26EBAQwC+//MK+fftIS0tj9uzZ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EfjQZrONNJlMDYEIoDlwCphks9kMAJPJ9CGQAtQG2gEHgH42m+3Xm9VLgaCAFixYQExMDJs2bcJkMvHss88yf/58xo0bB8CpU6c4e/Ys0dHRxMTEMHDgQBo3bkzdunV58cUXWbx4MaGhoZw7d47jx49Trlw5Pv7442uGDN5//302bNjAypUrqVatGpMmTWLixIksXLjQvs3OnTv59ttvi+W+2cUpMzOTQYMG0bZtW6KionBxceHnn3/m2LFj7N69m169erF3716WLVvGiy++SHR09DVttG7dOubMmcOSJUto0qQJcXFxlClTJs82e/fuZciQIUybNo3HHnsMq9XK4MGD6dixI++++y4nT56kT58+3HfffbRv3x6AzZs38/777zN37lzeeustJk6caA+Pd6Wcjv3qGfGO7tiv/qpbPh27ZsNLcbj6fWXatGlA1lyCUaNGXTNk8N///jdnyKACgMlkKg9sBiYDTwKNgU0mk2m/zWbbn12sL/AEEEPWnYTfBPrcrG4KBAW0evVq3njjDfvNO1544QXGjx9vDwQA48aNw83NjdatW/Poo4+ybt06wsPDMZvN/PLLLwQEBFClShWq3OBSlcuWLeOf//xnzgUpGDt2LC1btiQj1ynPsWPHUq5cOQe90pJr9+7dJCUlMWnSJPtQScuWLTl27Bh+fn70798fAIvFwiuvvMKpU6eoUSPvjTQ//fRT/va3v9E0+5riderUybN+165dfPrppyxYsIC2bdsCsGfPHs6cOUN4eDgAtWrVol+/fqxZs8YeCFq0aMGjjz4KQI8ePfjggw8c0wjOZrVeM3nONdckOod07DVrXvtVt9q1yaxdW5/YpVTK733lNnQG4mw227+zn8eYTKbPgJ5ATiBYZbPZdgGYTKblwJxrd3MtBYICSkpKws/Pz/7cz8+PpKQk+/PKlSvn6aRzr3///feZP38+06dPp1GjRkyYMIH7778/3+OcOHGCoUOH4uLiYl/m6urKqVOn7M9zwsLdJiEhAT8/v3znTXh5edkfe2R3GikpKfnuo1atWtc9xscff0yrVq3y/NGeOHGCpKQkGjVqZF+WmZlJaGio/Xnu4OHh4UFaWlrJmuOhjl2k2OT3vnIbagGh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H+OLOPduBMQQxHddbj1JmEQERERK6srnQZiIiIyFUoIRARERElBCIiIqKEQERERFBCICIiIighEBEREZQQiNRZxpj1xpgn3R2HiNwYlBCIiIiIFiYSuRkYYyKB2UAXnER/MXACaGmtHeI6Jgo4CPgBE3Ee8HMRZ4W5Rdba4caYVsAbQCecJwROsNZa1/mLcB4MFIXzOOE9wCBr7X7X+1c79yGcp+JFAj8Cs6y1040xIcAioDPOqpe7gXhrbfEKmCJynaiFQMTDGWN8gE+AQzg36+JlY6/IWjsOZ/np4dbaX7iSgUBgNfC/OI8CHgi8aYxpW+rUgTjJRENgHzDZFcO1zn0LeNpaewvQDljr2j8K5+FDTYBQnCWw9S1FxA18r32IiNzg7sF59OyYUs+g/9wY82Alr5MApFtrU13bXxljluE8pGa3a9+H1tqtAMaY94CZFTz3ItDGGLPTWnsKOOU67iLQDLjNWrsPJ0kRETdQQiDi+SKBQ6WSgaq6DYg1xpwutc8XeLfUdnap1z8Bv6jguX2A8cBUY8y/gRettZuBacDLwKfGGID51tqp1fw9RKQKlBCIeL4M4FZjjG+5pOAc0KDUdli588o3zWcAn1lre1Qxhiuea639Ekg0xvgBw3GeMhhprT2D020wytW9sM4Y86W1Nq0KMYhINSghEPF8W4GjON++/wwU4Azs+xr4ozHmVuAHYGy583KA20ttf+K6xqP8PAahA3DWWrv3GjFc8VxgP9AP+MRa+4Mx5kdXjBhjEoD/cx1TvL+gEr+7iNQQDSoU8XDW2gKgN9ASOIwzSK+/tXY1sBT4N7Ad56Zd2mygrzHmlDHmdde39V8DA4AsnO6BV4GACsRwrXMfBdJdycAzwBDX/mhgDU7isBl401q7vpJFICI1QNMORURERC0EIiIiooRAREREUEIgIiIiKCEQERERlBCIiIgISghEREQEJQQiIiKCEgIREREB/h+5hL/xQMASlgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 576x576 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(8, 8))\n",
    "plt.scatter([item[0] for item in animal_lookup.values()],\n",
    "            [item[1] for item in animal_lookup.values()])\n",
    "plt.xlabel('cuteness')\n",
    "plt.ylabel('size')\n",
    "for label, (cute, size) in animal_lookup.items():\n",
    "    plt.text(cute+1, size+1, label, fontsize=12)\n",
    "plt.arrow(\n",
    "    *(animal_lookup['tarantula']),\n",
    "    *(np.array(animal_lookup['hamster']) - np.array(animal_lookup['tarantula'])),\n",
    "    fc=\"b\", ec=\"b\", head_width=1.5, head_length=2, linewidth=1.5)\n",
    "plt.arrow(\n",
    "    *(animal_lookup['chicken']),\n",
    "    *(np.array(animal_lookup['hamster']) - np.array(animal_lookup['tarantula'])),\n",
    "    fc=\"r\", ec=\"r\", head_width=1.5, head_length=2, linewidth=1.5)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can understand this arrow as being the *relationship* between a tarantula and a hamster, in terms of their size and cuteness (i.e., hamsters and tarantulas are about the same size, but hamsters are much cuter). In the same diagram, I've also transposed this same arrow (this time in red) so that its origin point is \"chicken.\" The arrow ends closest to \"kitten.\" What we've discovered is that the animal that is about the same size as a chicken but much cuter is... a kitten. To put it in terms of an analogy:\n",
    "\n",
    "    Tarantulas are to hamsters as chickens are to kittens.\n",
    "    \n",
    "A sequence of numbers used to identify a point is called a *vector*, and the kind of math we've been doing so far is called *linear algebra.* (Linear algebra is surprisingly useful across many domains: It's the same kind of math you might do to, e.g., simulate the velocity and acceleration of a sprite in a video game.)\n",
    "\n",
    "A set of vectors that are all part of the same data set is often called a *vector space*. The vector space of animals in this section has two *dimensions*, by which I mean that each vector in the space has two numbers associated with it (i.e., two columns in the spreadsheet). The fact that this space has two dimensions just happens to make it easy to *visualize* the space by drawing a 2D plot. But most vector spaces you'll work with will have more than two dimensions—sometimes many hundreds. In those cases, it's more difficult to visualize the \"space,\" but the math works pretty much the same."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Language with vectors: colors\n",
    "\n",
    "So far, so good. We have a system in place—albeit highly subjective—for talking about animals and the words used to name them. I want to talk about another vector space that has to do with language: the vector space of colors.\n",
    "\n",
    "Colors are often represented in computers as vectors with three dimensions: red, green, and blue. Just as with the animals in the previous section, we can use these vectors to answer questions like: which colors are similar? What's the most likely color name for an arbitrarily chosen set of values for red, green and blue? Given the names of two colors, what's the name of those colors' \"average\"?\n",
    "\n",
    "We'll be working with this [color data](https://github.com/dariusk/corpora/blob/master/data/colors/xkcd.json) from the [xkcd color survey](https://blog.xkcd.com/2010/05/03/color-survey-results/). The data relates a color name to the RGB value associated with that color. [Here's a page that shows what the colors look like](https://xkcd.com/color/rgb/). Download the color data and put it in the same directory as this notebook.\n",
    "\n",
    "A few notes before we proceed:\n",
    "\n",
    "* We're using `numpy` arrays below to implement vector arithmetic. You'll need to install `numpy` to get the examples to work. (If you used Anaconda to install Python, you have `numpy` already.) [Here's a quick introduction on how to use numpy for vector arithmetic.](https://docs.scipy.org/doc/numpy/user/quickstart.html)\n",
    "* If you're interested in perceptually accurate color math in Python, consider using the [colormath library](http://python-colormath.readthedocs.io/en/latest/).\n",
    "\n",
    "Now, import the `json` library and load the color data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "color_data = json.loads(open(\"xkcd.json\").read())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following function converts colors from hex format (`#1a2b3c`) to a tuple of integers:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def hex_to_int(s):\n",
    "    s = s.lstrip(\"#\")\n",
    "    return np.array([int(s[:2], 16), int(s[2:4], 16), int(s[4:6], 16)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And the following cell creates a dictionary and populates it with mappings from color names to RGB vectors for each color in the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "colors = dict()\n",
    "for item in color_data['colors']:\n",
    "    colors[item[\"color\"]] = hex_to_int(item[\"hex\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Testing it out:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([110, 117,  14])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "colors['olive']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([229,   0,   0])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "colors['red']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "colors['black']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0, 255, 255])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "colors['cyan']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Vector math\n",
    "\n",
    "Before we keep going, we'll need some functions for performing basic vector \"arithmetic.\" These functions will work with vectors in spaces of any number of dimensions.\n",
    "\n",
    "The first function returns the Euclidean distance between two points:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy.linalg import norm\n",
    "def distance(a, b):\n",
    "    return norm(a - b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "190.7275543805876"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distance(colors['cyan'], colors['blue'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.0990195135927845"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distance(np.array([10, 1]), np.array([5, 2]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Subtracting vectors:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ -3, 188,  32])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "colors['cyan'] - colors['blue']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Adding vectors:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  3, 322, 478])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "colors['cyan'] + colors['blue']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can find the average of two vectors using the expected formula:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  1.5, 161. , 239. ])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(colors['cyan'] + colors['blue']) / 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or use the following function, which finds the mean of any number of vectors:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "def meanv(vecs):\n",
    "    total = np.sum(vecs, axis=0)\n",
    "    return total / len(vecs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([195.,  43.,  75.])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "meanv([colors['red'], colors['pink'], colors['maroon']])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Just as a test, the following cell shows that the distance from \"red\" to \"green\" is greater than the distance from \"red\" to \"pink\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distance(colors['red'], colors['green']) > distance(colors['red'], colors['pink'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Finding the closest item\n",
    "\n",
    "Just as we wanted to find the animal that most closely matched an arbitrary point in cuteness/size space, we'll want to find the closest color name to an arbitrary point in RGB space. The easiest way to find the closest item to an arbitrary vector is simply to find the distance between the target vector and each item in the space, in turn, then sort the list from closest to most distant.\n",
    "\n",
    "Calculating the distance between two points, however, is computationally expensive, especially when you're working with data that has many dimensions. To solve this problem, computer scientists and mathematicians came up with the idea of [approximate nearest neighbor search](https://en.wikipedia.org/wiki/Nearest_neighbor_search#Approximation_methods), a technique for finding similar points in high-dimensional spaces that make use of various tricks to speed up the process (potentially at the cost of accuracy).\n",
    "\n",
    "We're going to use a library I made called [Simple Neighbors](https://github.com/aparrish/simpleneighbors) that builds such an approximate nearest neighbors index to quickly return the closest items for any given vector. (Simple Neighbors is based on [Annoy](https://pypi.python.org/pypi/annoy).)\n",
    "\n",
    "Install Simple Neighbors like so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: simpleneighbors in /Users/allison/anaconda/lib/python3.6/site-packages\n",
      "Requirement already satisfied: annoy in /Users/allison/anaconda/lib/python3.6/site-packages (from simpleneighbors)\n",
      "\u001b[33mYou are using pip version 9.0.3, however version 19.0.3 is available.\n",
      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install simpleneighbors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you get an error from the above, and you're using Anaconda, you can try installing the Anaconda package:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!conda install -y -c conda-forge python-annoy "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If neither of those works—especially if you're using Windows—you may need to install a C++ compiler, or you can use this notebook on Binder. (If you're a student, come see me for more info.)\n",
    "\n",
    "Once you have the library installed, import it like so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "from simpleneighbors import SimpleNeighbors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first parameter to `SimpleNeighbors()` is the number of dimensions in the data; the second is the distance metric to use. (This defaults to cosine distance, but in this case we want to use Euclidean distance.)\n",
    "\n",
    "The `.add_one()` method adds an item and a vector to the index. Once all the items are added, `.build()` actually builds the index. This should go quick, since we don't have that much data!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "color_lookup = SimpleNeighbors(3, 'euclidean')\n",
    "for name, vec in colors.items():\n",
    "    color_lookup.add_one(name, vec)\n",
    "color_lookup.build()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To find the nearest item to a specified vector, pass the vector to the `.nearest()` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['red',\n",
       " 'fire engine red',\n",
       " 'bright red',\n",
       " 'tomato red',\n",
       " 'cherry red',\n",
       " 'scarlet',\n",
       " 'vermillion',\n",
       " 'orangish red',\n",
       " 'cherry',\n",
       " 'lipstick red',\n",
       " 'darkish red',\n",
       " 'neon red']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.nearest(colors['red'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Limit the number of results returned with the second parameter:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['red', 'fire engine red', 'bright red']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.nearest(colors['red'], 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here are the colors closest to (150, 60, 150):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['warm purple',\n",
       " 'medium purple',\n",
       " 'ugly purple',\n",
       " 'light eggplant',\n",
       " 'purpleish',\n",
       " 'purplish',\n",
       " 'purply',\n",
       " 'light plum',\n",
       " 'purple',\n",
       " 'muted purple',\n",
       " 'dusty purple',\n",
       " 'dusky purple']"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.nearest([150, 60, 150])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `.dist()` method gives the distance between two items in the index:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "94.28679656982422"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.dist('rose', 'pink')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "221.90313720703125"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.dist('green', 'purple')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And you can check the `.corpus` attribute to see if an item is even in the index to begin with:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'orange' in color_lookup.corpus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'kitten' in color_lookup.corpus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Color magic\n",
    "\n",
    "The magical part of representing words as vectors is that the vector operations we defined earlier appear to operate on language the same way they operate on numbers. For example, if we find the word closest to the vector resulting from subtracting \"red\" from \"purple,\" we get a series of \"blue\" colors:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['cobalt blue',\n",
       " 'royal blue',\n",
       " 'darkish blue',\n",
       " 'true blue',\n",
       " 'royal',\n",
       " 'prussian blue',\n",
       " 'dark royal blue',\n",
       " 'deep blue',\n",
       " 'marine blue',\n",
       " 'deep sea blue',\n",
       " 'darkblue',\n",
       " 'twilight blue']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.nearest(colors['purple'] - colors['red'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This matches our intuition about RGB colors, which is that purple is a combination of red and blue. Take away the red, and blue is all you have left.\n",
    "\n",
    "You can do something similar with addition. What's blue plus green?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['bright turquoise',\n",
       " 'bright light blue',\n",
       " 'bright aqua',\n",
       " 'cyan',\n",
       " 'neon blue',\n",
       " 'aqua blue',\n",
       " 'bright cyan',\n",
       " 'bright sky blue',\n",
       " 'aqua',\n",
       " 'bright teal',\n",
       " 'aqua marine',\n",
       " 'greenish cyan']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.nearest(colors['blue'] + colors['green'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "That's right, it's something like turquoise or cyan! What if we find the average of black and white? Predictably, we get gray:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['medium grey',\n",
       " 'purple grey',\n",
       " 'steel grey',\n",
       " 'battleship grey',\n",
       " 'grey purple',\n",
       " 'purplish grey',\n",
       " 'greyish purple',\n",
       " 'steel',\n",
       " 'warm grey',\n",
       " 'green grey',\n",
       " 'brown grey',\n",
       " 'bluish grey']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the average of black and white: medium grey\n",
    "color_lookup.nearest(meanv([colors['white'], colors['black']]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Just as with the tarantula/hamster example from the previous section, we can use color vectors to reason about relationships between colors. In the cell below, finding the difference between \"pink\" and \"red\" then adding it to \"blue\" seems to give us a list of colors that are to blue what pink is to red (i.e., a slightly lighter, less saturated shade):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['neon blue',\n",
       " 'bright sky blue',\n",
       " 'bright light blue',\n",
       " 'cyan',\n",
       " 'bright cyan',\n",
       " 'bright turquoise',\n",
       " 'clear blue',\n",
       " 'azure',\n",
       " 'dodger blue',\n",
       " 'lightish blue',\n",
       " 'sky blue',\n",
       " 'aqua blue']"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# an analogy: pink is to red as X is to blue\n",
    "pink_to_red = colors['pink'] - colors['red']\n",
    "color_lookup.nearest(pink_to_red + colors['blue'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another example of color analogies: Navy is to blue as true green/dark grass green is to green:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['true green',\n",
       " 'dark grass green',\n",
       " 'grassy green',\n",
       " 'racing green',\n",
       " 'forest',\n",
       " 'bottle green',\n",
       " 'dark olive green',\n",
       " 'darkgreen',\n",
       " 'forrest green',\n",
       " 'grass green',\n",
       " 'navy green',\n",
       " 'deep green']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# another example: \n",
    "navy_to_blue = colors['navy'] - colors['blue']\n",
    "color_lookup.nearest(navy_to_blue + colors['green'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The examples above are fairly simple from a mathematical perspective but nevertheless *feel* magical: they're demonstrating that it's possible to use math to reason about how people use language."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Interlude: A Love Poem That Loses Its Way"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Roses are red, violets are blue\n",
      "Roses are neon red, violets are vivid blue\n",
      "Roses are lightish red, violets are rich blue\n",
      "Roses are neon red, violets are blue\n",
      "Roses are red pink, violets are blue blue\n",
      "Roses are pink red, violets are blurple\n",
      "Roses are cerise, violets are bluish purple\n",
      "Roses are ruby, violets are blurple\n",
      "Roses are lipstick, violets are purpley blue\n",
      "Roses are red pink, violets are blue with a hint of purple\n",
      "Roses are pinky red, violets are dark periwinkle\n",
      "Roses are tomato, violets are blue with a hint of purple\n",
      "Roses are reddish orange, violets are purpley blue\n",
      "Roses are orange red, violets are purple blue\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "red = colors['red']\n",
    "blue = colors['blue']\n",
    "for i in range(14):\n",
    "    rednames = color_lookup.nearest(red)\n",
    "    bluenames = color_lookup.nearest(blue)\n",
    "    print(\"Roses are \" + rednames[0] + \", violets are \" + bluenames[0])\n",
    "    red = colors[random.choice(rednames[1:])]\n",
    "    blue = colors[random.choice(bluenames[1:])]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Doing bad digital humanities with color vectors\n",
    "\n",
    "With the tools above in hand, we can start using our vectorized knowledge of language toward academic ends. In the following example, I'm going to calculate the average color of Mary Shelley's *Frankenstein*.\n",
    "\n",
    "(Before you proceed, make sure to [download the text file from Project Gutenberg](http://www.gutenberg.org/files/84/84-0.txt) and place it in the same directory as this notebook.)\n",
    "\n",
    "First, we'll load [spaCy](https://spacy.io/). (Note: For the rest of this tutorial to work, you'll want to download at least the medium model for English. The default \"small\" model doesn't include word vectors.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "import spacy\n",
    "nlp = spacy.load('en_core_web_md')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To calculate the average color, we'll follow these steps:\n",
    "\n",
    "1. Parse the text into words\n",
    "2. Check every word to see if it names a color in our vector space. If it does, add it to a list of vectors.\n",
    "3. Find the average of that list of vectors.\n",
    "4. Find the color(s) closest to that average vector.\n",
    "\n",
    "The following cell performs steps 1-3:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[125.52050473 134.0851735  121.63722397]\n"
     ]
    }
   ],
   "source": [
    "doc = nlp(open(\"84-0.txt\").read())\n",
    "# use word.lower_ to normalize case\n",
    "drac_colors = [colors[word.lower_] for word in doc if word.lower_ in colors]\n",
    "avg_color = meanv(drac_colors)\n",
    "print(avg_color)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we'll pass the averaged color vector to the `closest()` function, yielding... well, it's just a grey mush, which is kinda what you'd expect from adding a bunch of colors together willy-nilly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['medium grey',\n",
       " 'green grey',\n",
       " 'steel grey',\n",
       " 'grey green',\n",
       " 'brown grey',\n",
       " 'battleship grey',\n",
       " 'greeny grey',\n",
       " 'purple grey',\n",
       " 'warm grey',\n",
       " 'grey/green',\n",
       " 'slate green',\n",
       " 'steel']"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "color_lookup.nearest(avg_color)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "On the other hand, here's what we get when we average the colors of Charlotte Perkins Gilman's classic *The Yellow Wallpaper*. ([Download from here](http://www.gutenberg.org/cache/epub/1952/pg1952.txt) and save in the same directory as this notebook if you want to follow along.) The result definitely reflects the content of the story, so maybe we're on to something here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['pea',\n",
       " 'puke yellow',\n",
       " 'sick green',\n",
       " 'vomit yellow',\n",
       " 'booger',\n",
       " 'olive yellow',\n",
       " 'snot',\n",
       " 'gross green',\n",
       " 'dirty yellow',\n",
       " 'mustard yellow',\n",
       " 'dark yellow',\n",
       " 'baby puke green']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "doc = nlp(open(\"1952-0.txt\").read())\n",
    "wallpaper_colors = [colors[word.lower_] for word in doc if word.lower_ in colors]\n",
    "avg_color = meanv(wallpaper_colors)\n",
    "color_lookup.nearest(avg_color)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Exercise for the reader: Use the vector arithmetic functions to rewrite a text, making it...\n",
    "\n",
    "* more blue (i.e., add `colors['blue']` to each occurrence of a color word); or\n",
    "* more light (i.e., add `colors['white']` to each occurrence of a color word); or\n",
    "* darker (i.e., attenuate each color. You might need to write a vector multiplication function to do this one right.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Distributional semantics\n",
    "\n",
    "In the previous section, the examples are interesting because of a simple fact: colors that we think of as similar are \"closer\" to each other in RGB vector space. In our color vector space, or in our animal cuteness/size space, you can think of the words identified by vectors close to each other as being *synonyms*, in a sense: they sort of \"mean\" the same thing. They're also, for many purposes, *functionally identical*. Think of this in terms of writing, say, a search engine. If someone searches for \"mauve trousers,\" then it's probably also okay to show them results for, say,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mauve trousers\n",
      "dusty rose trousers\n",
      "dusky rose trousers\n",
      "brownish pink trousers\n",
      "old pink trousers\n",
      "reddish grey trousers\n",
      "dirty pink trousers\n",
      "old rose trousers\n",
      "light plum trousers\n",
      "ugly pink trousers\n",
      "pinkish brown trousers\n",
      "dusky pink trousers\n"
     ]
    }
   ],
   "source": [
    "for cname in color_lookup.nearest(colors['mauve']):\n",
    "    print(cname + \" trousers\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "That's all well and good for color words, which intuitively seem to exist in a multidimensional continuum of perception, and for our animal space, where we've written out the vectors ahead of time. But what about... arbitrary words? Is it possible to create a vector space for all English words that has this same \"closer in space is closer in meaning\" property?\n",
    "\n",
    "To answer that, we have to back up a bit and ask the question: what does *meaning* mean? No one really knows, but one theory popular among computational linguists, computer scientists and other people who make search engines is the [Distributional Hypothesis](https://en.wikipedia.org/wiki/Distributional_semantics), which states that:\n",
    "\n",
    "    Linguistic items with similar distributions have similar meanings.\n",
    "    \n",
    "What's meant by \"similar distributions\" is *similar contexts*. Take for example the following sentences:\n",
    "\n",
    "    It was really cold yesterday.\n",
    "    It will be really warm today, though.\n",
    "    It'll be really hot tomorrow!\n",
    "    Will it be really cool Tuesday?\n",
    "    \n",
    "According to the Distributional Hypothesis, the words `cold`, `warm`, `hot` and `cool` must be related in some way (i.e., be close in meaning) because they occur in a similar context, i.e., between the word \"really\" and a word indicating a particular day. (Likewise, the words `yesterday`, `today`, `tomorrow` and `Tuesday` must be related, since they occur in the context of a word indicating a temperature.)\n",
    "\n",
    "In other words, according to the Distributional Hypothesis, a word's meaning is just a big list of all the contexts it occurs in. Two words are closer in meaning if they share contexts."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Word vectors by counting contexts\n",
    "\n",
    "So how do we turn this insight from the Distributional Hypothesis into a system for creating general-purpose vectors that capture the meaning of words? Maybe you can see where I'm going with this. What if we made a *really big* spreadsheet that had one column for every context for every word in a given source text. Let's use a small source text to begin with, such as this excerpt from Dickens:\n",
    "\n",
    "    It was the best of times, it was the worst of times.\n",
    "\n",
    "Such a spreadsheet might look something like this:\n",
    "\n",
    "![dickens contexts](http://static.decontextualize.com/snaps/best-of-times.png)\n",
    "\n",
    "The spreadsheet has one column for every possible context, and one row for every word. The values in each cell correspond with how many times the word occurs in the given context. The numbers in the columns constitute that word's vector, i.e., the vector for the word `of` is\n",
    "\n",
    "    [0, 0, 0, 0, 1, 0, 0, 0, 1, 0]\n",
    "    \n",
    "Because there are ten possible contexts, this is a ten dimensional space! It might be strange to think of it, but you can do vector arithmetic on vectors with ten dimensions just as easily as you can on vectors with two or three dimensions, and you could use the same distance formula that we defined earlier to get useful information about which vectors in this space are similar to each other. In particular, the vectors for `best` and `worst` are actually the same (a distance of zero), since they occur only in the same context (`the ___ of`):\n",
    "\n",
    "    [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]\n",
    "    \n",
    "Of course, the conventional way of thinking about \"best\" and \"worst\" is that they're *antonyms*, not *synonyms*. But they're also clearly two words of the same kind, with related meanings (through opposition), a fact that is captured by this distributional model.\n",
    "\n",
    "### Contexts and dimensionality\n",
    "\n",
    "Of course, in a corpus of any reasonable size, there will be many thousands if not many millions of possible contexts. It's difficult enough working with a vector space of ten dimensions, let alone a vector space of a million dimensions! It turns out, though, that many of the dimensions end up being superfluous and can either be eliminated or combined with other dimensions without significantly affecting the predictive power of the resulting vectors. The process of getting rid of superfluous dimensions in a vector space is called [dimensionality reduction](https://en.wikipedia.org/wiki/Dimensionality_reduction), and most implementations of count-based word vectors make use of dimensionality reduction so that the resulting vector space has a reasonable number of dimensions (say, 100—300, depending on the corpus and application).\n",
    "\n",
    "The question of how to identify a \"context\" is itself very difficult to answer. In the toy example above, we've said that a \"context\" is just the word that precedes and the word that follows. Depending on your implementation of this procedure, though, you might want a context with a bigger \"window\" (e.g., two words before and after), or a non-contiguous window (skip a word before and after the given word). You might exclude certain \"function\" words like \"the\" and \"of\" when determining a word's context, or you might [lemmatize](https://en.wikipedia.org/wiki/Lemmatisation) the words before you begin your analysis, so two occurrences with different \"forms\" of the same word count as the same context. These are all questions open to research and debate, and different implementations of procedures for creating count-based word vectors make different decisions on this issue.\n",
    "\n",
    "### GloVe vectors\n",
    "\n",
    "But you don't have to create your own word vectors from scratch! Many researchers have made downloadable databases of pre-trained vectors. One such project is Stanford's [Global Vectors for Word Representation (GloVe)](https://nlp.stanford.edu/projects/glove/). These 300-dimensional vectors are included with spaCy, and they're the vectors we'll be using for the rest of this tutorial."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Word vectors in spaCy\n",
    "\n",
    "Okay, let's have some fun with real word vectors. We're going to use the GloVe vectors that come with spaCy to creatively analyze and manipulate the text of *Frankenstein*. First, make sure you've got `spacy` imported:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [],
   "source": [
    "import spacy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following cell loads the language model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "nlp = spacy.load('en_core_web_md')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can see the vector of any word in spaCy's vocabulary using the `vocab` attribute, like so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-2.2743e-01, -5.1464e-02, -4.3421e-02, -1.0523e-01, -3.3389e-01,\n",
       "       -4.9611e-01, -6.4342e-01, -4.6994e-01,  3.9693e-01,  8.4902e-01,\n",
       "       -4.0845e-01, -1.8312e-01, -6.2564e-01, -1.0160e-01, -3.6914e-01,\n",
       "        6.8634e-01,  2.6607e-01,  3.2985e-01, -9.8570e-02, -1.3281e-01,\n",
       "       -4.7505e-01, -1.9249e-01, -3.1917e-01, -1.8536e-01,  1.1118e-01,\n",
       "        7.3772e-02, -3.0407e-01, -2.7552e-01,  6.1108e-01, -3.6344e-01,\n",
       "       -4.5849e-01, -1.2872e-01,  1.5175e-01,  3.3248e-01,  3.0900e-01,\n",
       "       -2.8488e-01,  2.5544e-01, -9.4332e-01, -5.5746e-01,  5.8764e-02,\n",
       "        1.1174e-01,  2.0032e-01, -4.1090e-01, -5.4444e-01, -4.3831e-02,\n",
       "        1.6265e-01, -6.8028e-01,  2.8266e-01,  1.8177e-01, -5.6184e-01,\n",
       "        7.0911e-02, -3.4996e-01, -3.1639e-01,  1.7666e-01, -9.4568e-03,\n",
       "        4.4389e-01,  7.6684e-02, -2.1797e-01,  1.3728e-03,  2.3474e-01,\n",
       "       -1.8564e-01, -4.2277e-01,  2.5585e-01, -6.2553e-01, -1.4335e-01,\n",
       "       -1.8835e-01,  3.5240e-01,  2.0764e-01,  8.8644e-02, -2.0873e-01,\n",
       "       -3.9081e-01, -1.5079e-01, -3.4469e-01, -3.2128e-01, -1.2094e-01,\n",
       "       -6.6444e-03, -1.6742e-01, -3.5412e-01,  3.5457e-01, -6.8729e-01,\n",
       "        4.2718e-01,  3.2739e-01, -5.2189e-01,  1.9016e-01, -2.0203e-01,\n",
       "       -2.5103e-02,  1.4170e+00,  5.4864e-01,  6.3232e-01,  9.1078e-02,\n",
       "        1.6614e-01,  6.4225e-01,  9.4285e-02, -5.8877e-01, -5.8017e-01,\n",
       "        2.4200e-02, -5.9718e-02, -2.0356e-01,  3.6787e-01, -2.1599e-04,\n",
       "        1.2642e-01,  2.1863e-01,  1.4783e-01,  1.1456e-01,  5.1725e-01,\n",
       "       -5.2379e-01,  1.9920e-01, -3.4157e-01, -4.5679e-01, -3.6249e-01,\n",
       "       -1.5894e-01,  4.1326e-01,  3.3038e-01, -6.0792e-01,  3.3837e-02,\n",
       "       -1.3185e-01, -2.3943e-01,  2.0958e-01,  5.4647e-01, -1.6166e-01,\n",
       "       -8.4986e-02, -3.7066e-03,  4.1813e-01, -6.2813e-01, -1.5596e-01,\n",
       "        2.7174e-01,  2.6749e-01, -3.1466e-01, -3.0005e-01, -1.1754e-03,\n",
       "       -7.6564e-02, -4.1596e-01, -5.1201e-01,  3.3995e-01,  3.3515e-01,\n",
       "        2.3181e-01, -2.3126e-01,  6.4867e-01, -1.7327e-01,  2.1906e-01,\n",
       "       -2.4825e+00, -3.8253e-01, -2.7501e-01,  3.8250e-01,  3.9909e-01,\n",
       "       -3.4766e-01, -3.4750e-01,  1.1423e-01,  3.8426e-01, -4.5397e-02,\n",
       "        3.3079e-01,  3.0611e-01, -1.6365e-01, -2.1840e-01, -4.9622e-01,\n",
       "        3.2069e-01, -1.0056e-01,  4.7965e-01, -6.1692e-01, -7.1039e-01,\n",
       "        6.7294e-03, -1.3760e-01, -2.4534e-01, -6.3200e-01, -1.3581e-01,\n",
       "        5.0657e-02, -2.6497e-01,  4.7350e-02, -2.1670e-01,  1.1975e-01,\n",
       "       -1.5930e-01,  6.5097e-02,  6.2833e-01, -4.1485e-01, -4.9077e-01,\n",
       "        5.3359e-01, -2.8512e-01, -6.8738e-02, -1.5921e-01,  7.1961e-01,\n",
       "       -9.9519e-02, -4.4382e-01,  1.2937e-01, -3.0042e-01, -4.5345e-01,\n",
       "       -1.2133e-01, -5.7589e-02,  1.7615e-03, -1.4016e-01, -5.4348e-01,\n",
       "       -2.7313e-01,  7.9147e-02,  9.2326e-02, -3.2881e-01,  4.2704e-01,\n",
       "        2.2025e-01, -2.8184e-01, -1.0668e-01,  7.8995e-01,  1.0433e-01,\n",
       "       -7.1160e-01,  5.0875e-01, -4.4899e-01, -1.5814e-01,  8.9031e-02,\n",
       "        1.9779e-01,  1.7832e-01, -1.5837e-01,  4.1920e-01,  1.1525e-01,\n",
       "       -5.6151e-01,  1.5977e-03, -6.3471e-01,  1.7369e-01, -1.6660e-01,\n",
       "        1.1221e-01, -6.8455e-02,  2.5285e-01,  3.2207e-01, -9.7379e-02,\n",
       "       -6.0705e-02,  2.1614e-03,  4.7962e-01, -6.2126e-01, -3.8508e-01,\n",
       "       -3.3929e-02,  1.6450e-01,  8.4856e-01,  1.6799e-01,  7.0092e-02,\n",
       "       -3.7176e-01,  3.3799e-01, -4.4381e-01, -4.1767e-01,  4.5403e-01,\n",
       "       -1.2410e-01, -1.2079e-01, -1.7261e-01,  6.0124e-01, -4.0454e-01,\n",
       "       -7.5649e-01, -8.0093e-02, -4.0163e-01,  1.4112e-01, -1.0350e-01,\n",
       "       -3.3089e-02,  1.1493e-01,  5.8734e-01,  3.3808e-01,  2.3712e-01,\n",
       "       -1.8119e-01, -9.0462e-02, -7.5090e-02,  3.0095e-01,  2.4288e-01,\n",
       "       -1.1910e-01, -7.9882e-01,  1.8590e-01,  1.8869e-01, -3.0644e-01,\n",
       "       -1.1699e-01, -1.9925e-01, -2.5868e-02, -1.9041e-01, -2.1018e-01,\n",
       "        3.7344e-01, -4.6269e-01, -2.2280e-01, -3.7530e-01, -2.1085e-02,\n",
       "       -4.1236e-01,  7.1003e-01, -1.3208e-01,  1.5749e-01, -2.3107e-01,\n",
       "        1.0245e-02,  1.2600e-01,  2.5397e-01,  4.6801e-02,  8.9900e-03,\n",
       "        2.9246e-01,  1.7141e-01,  1.7920e-01, -4.3189e-01,  5.1214e-01,\n",
       "        4.9256e-01,  3.1945e-01, -3.5943e-01,  1.0088e-01, -3.7515e-01,\n",
       "        2.1281e-02,  2.0247e-01, -3.4238e-02,  3.3511e-01, -4.2808e-01,\n",
       "        7.4968e-01, -1.2136e-01,  4.3539e-01,  1.5098e-01, -1.5952e-01],\n",
       "      dtype=float32)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nlp.vocab['kitten'].vector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "spaCy's English model uses 300-dimensional pre-trained GloVe vectors."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For the sake of convenience, the following function gets the vector of a given string from spaCy's vocabulary:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "def vec(s):\n",
    "    return nlp.vocab[s].vector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Another thing about spaCy vocab items: they have a `.prob` attribute that tells you the \"log probability\" of the token (i.e., its unigram frequency, passed to the `log()` function to make it more \"numerically stable\"). Basically, the closer to zero, the more common the word is; the further away from zero, the less common."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-5.846089839935303"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nlp.vocab[\"me\"].prob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-12.040445327758789"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nlp.vocab[\"kitten\"].prob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-19.401931762695312"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nlp.vocab[\"zymurgy\"].prob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Unknown tokens are assigned `-20.0`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-20.0"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nlp.vocab[\"QOWEIFAKLSDHF\"].prob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Looking up synonyms\n",
    "\n",
    "Here I make a `SimpleNeighbors` index that loads in all words from spaCy's vocab that (a) have an associated vector; (b) have a log probability greater than -15; (c) are lower case. (All but the first of these criteria are arbitrary; feel free to experiment.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {},
   "outputs": [],
   "source": [
    "lookup = SimpleNeighbors(300)\n",
    "for item in nlp.vocab:\n",
    "    if item.has_vector and item.prob > -15 and item.is_lower:\n",
    "        lookup.add_one(item.text, item.vector)\n",
    "lookup.build()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "32051"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(lookup)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can get synonyms for words by looking up the word's vector and finding the nearest word in the index:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['volleyball',\n",
       " 'lacrosse',\n",
       " 'basketball',\n",
       " 'bball',\n",
       " 'football',\n",
       " 'footballing',\n",
       " 'handball',\n",
       " 'soccer',\n",
       " 'softball',\n",
       " 'baseball',\n",
       " 'hockey',\n",
       " 'racket']"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookup.nearest(vec('basketball'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Fun with spaCy and vector arithmetic\n",
    "\n",
    "Now we can start doing vector arithmetic and finding the closest words to the resulting vectors. For example, what word is closest to the halfway point between day and night?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['night',\n",
       " 'day',\n",
       " 'evening',\n",
       " 'morning',\n",
       " 'midday',\n",
       " 'afternoon',\n",
       " 'nights',\n",
       " 'outing',\n",
       " 'weekend',\n",
       " 'days',\n",
       " 'hour',\n",
       " 'yesterday']"
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# halfway between day and night\n",
    "lookup.nearest(meanv([vec(\"day\"), vec(\"night\")]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Variations of `night` and `day` are still closest, but after that we get words like `evening` and `morning`, which are indeed halfway between day and night!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here are the closest words in *Frankenstein* to \"wine\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['wine',\n",
       " 'wines',\n",
       " 'tasting',\n",
       " 'sparkling',\n",
       " 'champagne',\n",
       " 'lager',\n",
       " 'beer',\n",
       " 'dropper',\n",
       " 'jug',\n",
       " 'bottle',\n",
       " 'drink',\n",
       " 'beverages']"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookup.nearest(vec(\"wine\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you subtract \"alcohol\" from \"wine\" and find the closest words to the resulting vector, you're left with simply a lovely dinner:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['chef',\n",
       " 'chefs',\n",
       " 'platters',\n",
       " 'dishes',\n",
       " 'delicious',\n",
       " 'decadent',\n",
       " 'savory',\n",
       " 'dessert',\n",
       " 'desserts',\n",
       " 'italian',\n",
       " 'carte',\n",
       " 'buffet']"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookup.nearest(vec(\"wine\") - vec(\"alcohol\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The closest words to \"water\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['seawater',\n",
       " 'water',\n",
       " 'dry',\n",
       " 'solvent',\n",
       " 'dispensing',\n",
       " 'liquid',\n",
       " 'heat',\n",
       " 'heats',\n",
       " 'gallons',\n",
       " 'cubic',\n",
       " 'quarts',\n",
       " 'litres']"
      ]
     },
     "execution_count": 228,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookup.nearest(vec(\"water\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But if you add \"frozen\" to \"water,\" you get \"ice\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['seawater',\n",
       " 'water',\n",
       " 'freezing',\n",
       " 'cold',\n",
       " 'chilly',\n",
       " 'heat',\n",
       " 'heats',\n",
       " 'dry',\n",
       " 'drying',\n",
       " 'ice',\n",
       " 'solvent',\n",
       " 'dispensing']"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookup.nearest(vec(\"water\") + vec(\"freezing\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can even do analogies! For example, the words most similar to \"grass\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['grass',\n",
       " 'sod',\n",
       " 'grassy',\n",
       " 'mulch',\n",
       " 'perennial',\n",
       " 'overgrown',\n",
       " 'weeds',\n",
       " 'herbicide',\n",
       " 'saplings',\n",
       " 'trees',\n",
       " 'foliage',\n",
       " 'bushes']"
      ]
     },
     "execution_count": 235,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookup.nearest(vec(\"grass\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you take the difference of \"blue\" and \"sky\" and add it to grass, you get the analogous word (\"green\"):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 236,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'periwinkle',\n",
       " 'violet',\n",
       " 'burgundy',\n",
       " 'teal',\n",
       " 'magenta',\n",
       " 'purple',\n",
       " 'pink',\n",
       " 'blue',\n",
       " 'indigo']"
      ]
     },
     "execution_count": 236,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# analogy: blue is to sky as X is to grass\n",
    "blue_to_sky = vec(\"blue\") - vec(\"sky\")\n",
    "lookup.nearest(blue_to_sky + vec(\"grass\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Replace with synonym\n",
    "\n",
    "The following example replaces all nouns, verbs and adjectives with a closely-related word from the synonym lookup."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "metadata": {},
   "outputs": [],
   "source": [
    "frost_doc = nlp(open(\"frost.txt\").read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Two roads diverged in a blue wood,\n",
      "And sorry I would not vacations both\n",
      "And should one traveler, long I sprang\n",
      "And looked down one as far as I would\n",
      "To where it thrusting in the cacti;\n",
      "\n",
      "Then took the different, as just as good,\n",
      "And being perhaps the much claimed,\n",
      "Because it was grassy and did wearer;\n",
      "Though as for that the passing there\n",
      "was wearing them really about the same,\n",
      "\n",
      "And both that midday equally lay\n",
      "In sprouted no step was treads white.\n",
      "Oh, I still the first for another day!\n",
      "Yet mind how going continues on to it,\n",
      "I doubting if I must ever they back.\n",
      "\n",
      "I must should telling this with a sighs\n",
      "Somewhere young and young hence:\n",
      "Two roads originates in a veneer, and I—\n",
      "I took the same less traveled by,\n",
      "And that is made all the comparing.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "output = []\n",
    "for word in frost_doc:\n",
    "    if word.is_alpha and word.pos_ in ('NOUN', 'VERB', 'ADJ'):\n",
    "        new_word = random.choice(lookup.nearest(word.vector, 3))\n",
    "        output.append(new_word)\n",
    "    else:\n",
    "        output.append(word.text)\n",
    "    output.append(word.whitespace_)\n",
    "print(''.join(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tinting meaning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "metadata": {},
   "outputs": [],
   "source": [
    "target_word = 'college'\n",
    "factor = 0.25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 261,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Two roads emergence in a turquoise mahogany,\n",
      "And sorry I have not trips both\n",
      "And if one collegiate, long I went\n",
      "And turned down one as far as I probably\n",
      "To where it shoulders in the foliage;\n",
      "\n",
      "Then bagged the local, as just as want,\n",
      "And one perhaps the enough that,\n",
      "Because it went gardening and going too;\n",
      "Though as for that the catch there\n",
      "did wore them really about the that,\n",
      "\n",
      "And both that evening equally away\n",
      "In out no foward had denier sexy.\n",
      "Oh, I being the collegiate for another every!\n",
      "Yet understand how way three on to make,\n",
      "I regret if I would ever coming back.\n",
      "\n",
      "I permissible already someone this with a oh\n",
      "Somewhere teenagers and age hence:\n",
      "Two potholes cultural in a woodwork, and I—\n",
      "I spent the only less visited by,\n",
      "And that being had every the much.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "output = []\n",
    "for word in frost_doc:\n",
    "    if word.is_alpha and word.pos_ in ('NOUN', 'VERB', 'ADJ'):\n",
    "        new_word = random.choice(lookup.nearest((word.vector*(1-factor)) + (vec(target_word)*factor)))\n",
    "        output.append(new_word)\n",
    "    else:\n",
    "        output.append(word.text)\n",
    "    output.append(word.whitespace_)\n",
    "print(''.join(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Semantic similarity search"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Every spaCy span (documents, sentences) has a `.vector` attribute that gives a \"summary\" vector for the span in question. (By default, this is calculated by averaging together all of the vectors.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "metadata": {},
   "outputs": [],
   "source": [
    "sent = nlp(\"Programming computers is fun!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.10907819,  0.1513352 ,  0.21237247, -0.15321401,  0.10914759,\n",
       "        0.0173588 ,  0.085984  , -0.2554782 ,  0.2094306 ,  1.6558399 ,\n",
       "       -0.09052315, -0.13296959,  0.0342764 ,  0.1505686 , -0.06614681,\n",
       "       -0.15527579, -0.1310828 ,  1.5044279 , -0.2026544 , -0.0886392 ,\n",
       "        0.0499612 , -0.1545334 , -0.1006914 ,  0.05445926,  0.26057976,\n",
       "       -0.00777239,  0.08823   , -0.0272476 ,  0.12919   , -0.12125119,\n",
       "       -0.24510416, -0.23006658,  0.09576257,  0.02779341,  0.157128  ,\n",
       "        0.10950659, -0.05011179,  0.319652  , -0.01529707,  0.05117084,\n",
       "        0.0409314 ,  0.167218  ,  0.0371664 ,  0.017644  ,  0.0630136 ,\n",
       "        0.27724802, -0.22601199, -0.0900348 ,  0.231374  ,  0.01768318],\n",
       "      dtype=float32)"
      ]
     },
     "execution_count": 290,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sent.vector[:50]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Interestingly, we can find the single word closest in meaning to this sequence of words:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['be',\n",
       " 'every',\n",
       " 'work',\n",
       " 'now',\n",
       " 'only',\n",
       " 'more',\n",
       " 'course',\n",
       " 'program',\n",
       " 'working',\n",
       " 'day',\n",
       " 'writing',\n",
       " 'composing']"
      ]
     },
     "execution_count": 291,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lookup.nearest(sent.vector)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's find the sentence in our text file that is closest in \"meaning\" to an arbitrary input sentence. First, we'll get the list of sentences:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 275,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc = nlp(open(\"./84-0.txt\").read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 279,
   "metadata": {},
   "outputs": [],
   "source": [
    "sentence_lookup = SimpleNeighbors(300)\n",
    "for sent in doc.sents:\n",
    "    sentence_lookup.add_one(sent.text.replace(\"\\n\", \" \"), sent.vector)\n",
    "sentence_lookup.build()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 285,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['When they had retired to rest, if there was any moon or the night was star-light, I went into the woods and collected my own food and fuel for the cottage.  ',\n",
       " 'This roused me from my nearly dormant state, and I ate some berries which I found hanging on the trees or lying on the ground.  ',\n",
       " 'Below this picture was a miniature of William; and my tears flowed when I looked upon it.',\n",
       " 'I was still cold when under one of the trees I found a huge cloak, with which I covered myself, and sat down upon the ground.  ',\n",
       " 'I could now almost fancy myself among the Swiss mountains.  ',\n",
       " 'I lay at the bottom of the boat, and as I gazed on the cloudless blue sky, I seemed to drink in a tranquillity to which I had long been a stranger.',\n",
       " 'I wish you could see him; he is very tall of his age, with sweet laughing blue eyes, dark eyelashes, and curling hair.  ',\n",
       " 'About five in the morning I discovered my lovely boy, whom the night before I had seen blooming and active in health, stretched on the grass livid and motionless; the print of the murder’s finger was on his neck.  ',\n",
       " 'It was noon when I awoke, and allured by the warmth of the sun, which shone brightly on the white ground, I determined to recommence my travels; and, depositing the remains of the peasant’s breakfast in a wallet I found, I proceeded across the fields for several hours, until at sunset I arrived at a village.  ',\n",
       " 'When it became noon, and the sun rose higher, I lay down on the grass and was overpowered by a deep sleep.  ',\n",
       " 'While I watched the tempest, so beautiful yet terrific, I wandered on with a hasty step.',\n",
       " 'Winter, spring, and summer passed away during my labours; but I did not watch the blossom or the expanding leaves—sights which before always yielded me']"
      ]
     },
     "execution_count": 285,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sentence_lookup.nearest(nlp(\"My favorite food is strawberry ice cream.\").vector)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A noun chunk lookup:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 317,
   "metadata": {},
   "outputs": [],
   "source": [
    "chunk_lookup = SimpleNeighbors(300)\n",
    "for chunk in doc.noun_chunks:\n",
    "    chunk_lookup.add_one(chunk.text.replace(\"\\n\", \" \"), chunk.vector)\n",
    "chunk_lookup.build()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 318,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['stately deer',\n",
       " 'its beautiful forest',\n",
       " 'the bleak forest',\n",
       " 'beautiful scenery',\n",
       " 'trees',\n",
       " 'trees',\n",
       " 'the dark mountains',\n",
       " 'the beautiful lake',\n",
       " 'the cloudless blue sky',\n",
       " 'the pine woods',\n",
       " 'the most verdant islands',\n",
       " 'the scenery']"
      ]
     },
     "execution_count": 318,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chunk_lookup.nearest(nlp(\"spooky birds\").vector)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 310,
   "metadata": {},
   "outputs": [],
   "source": [
    "adj_lookup = SimpleNeighbors(300)\n",
    "for word in doc:\n",
    "    if word.tag_ == 'JJ' and word.text not in adj_lookup.corpus:\n",
    "        adj_lookup.add_one(word.text, word.vector)\n",
    "adj_lookup.build()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1274"
      ]
     },
     "execution_count": 311,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(adj_lookup)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 313,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['awful',\n",
       " 'horrible',\n",
       " 'terrible',\n",
       " 'horrid',\n",
       " 'dreadful',\n",
       " 'bad',\n",
       " 'atrocious',\n",
       " 'hideous',\n",
       " 'Hideous',\n",
       " 'ghastly',\n",
       " 'hideousness',\n",
       " 'repulsive']"
      ]
     },
     "execution_count": 313,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adj_lookup.nearest(vec(\"awful\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rewriting with parts of speech from another text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 314,
   "metadata": {},
   "outputs": [],
   "source": [
    "frost_doc = nlp(open(\"frost.txt\").read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 319,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Two populous towns diverged in a yellow wood,\n",
      "And sorry I could not travel both\n",
      "And be one exquisite pleasure, long I stood\n",
      "And looked down one as far as I could\n",
      "To where it bent in the dark-leaved brambles;\n",
      "\n",
      "Then took the many, as just as honest,\n",
      "And having perhaps the better any argument,\n",
      "Because it was wet and wanted my neck;\n",
      "Though as for that the the path there\n",
      "Had worn them really about the only,\n",
      "\n",
      "And both that morning equally lay\n",
      "In dark-leaved brambles no some steps had trodden black.\n",
      "Oh, I kept the first for another day!\n",
      "Yet knowing how way leads on to way,\n",
      "I doubted if I should ever come back.\n",
      "\n",
      "I shall be telling this with a angry countenances\n",
      "Somewhere age and age hence:\n",
      "Two these rugged roads diverged in a wood, and I—\n",
      "I took the one less travelled by,\n",
      "And that has made all the a far different effect.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "output = []\n",
    "for word in frost_doc:\n",
    "    if word.is_alpha and word.pos_ == 'NOUN':\n",
    "        new_word = random.choice(chunk_lookup.nearest(word.vector, 5))\n",
    "        output.append(new_word)\n",
    "    elif word.is_alpha and word.tag_ == 'JJ':\n",
    "        new_word = random.choice(adj_lookup.nearest(word.vector, 5))\n",
    "        output.append(new_word)\n",
    "    else:\n",
    "        output.append(word.text)\n",
    "    output.append(word.whitespace_)\n",
    "print(''.join(output))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
